﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yinyue200.Sharp2D.Direct2D.Effects
{
    public class ArithmeticCompositeEffect : Effect
    {
        public override void GetEffectId(out Guid id)
        {
            id = SharpDX.Direct2D1.Effect.ArithmeticComposite;
        }
        public ArithmeticCompositeEffect()
        {
            Name = "ArithmeticCompositeEffect";
            pes.Add(null);
            SetBoxedProperty(Coefficients,Convert(PropertyValueOwner.CreateSingleArray(new float[] { 1, 0, 0, 0 })));
            SetBoxedProperty("ClampOutput", Convert(PropertyValueOwner.CreateBoolean(false)));
        }
        const string Coefficients = "Coefficients";
        public float MultiplyAmount
        {
            get
            {
                var vl = (float[])GetProperty(Coefficients);
                return vl[0];
            }
            set
            {
                var vl = (float[])GetProperty(Coefficients);
                vl[0] = value;
                SetProperty(Coefficients,Convert(PropertyValueOwner.CreateSingleArray( vl)));
            }
        }
        public float Source1Amount
        {
            get
            {
                var vl = (float[])GetProperty(Coefficients);
                return vl[1];
            }
            set
            {
                var vl = (float[])GetProperty(Coefficients);
                vl[1] = value;
                SetProperty(Coefficients, Convert(PropertyValueOwner.CreateSingleArray(vl)));
            }
        }
        public float Source2Amount
        {
            get
            {
                var vl = (float[])GetProperty(Coefficients);
                return vl[2];
            }
            set
            {
                var vl = (float[])GetProperty(Coefficients);
                vl[2] = value;
                SetProperty(Coefficients, Convert(PropertyValueOwner.CreateSingleArray(vl)));

            }
        }
        public float Offset
        {
            get
            {
                var vl = (float[])GetProperty(Coefficients);
                return vl[3];
            }
            set
            {
                var vl = (float[])GetProperty(Coefficients);
                vl[3] = value;
                SetProperty(Coefficients, Convert(PropertyValueOwner.CreateSingleArray(vl)));

            }
        }
        public bool ClampOutput
        {
            get
            {
                return (bool)GetProperty(nameof(ClampOutput));
            }
            set
            {
                SetProperty(nameof(ClampOutput), Convert(PropertyValueOwner.CreateBoolean(value)));
            }
        }


        public Windows.Graphics.Effects.IGraphicsEffectSource Source2
        {
            get
            {
                GetSource(1, out var source);
                return source;
            }
            set
            {
                pes[1] = value;
            }
        }

    }
}
